package com.zhongxi.guoyuan.adapter.rewardCoin;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.zhongxi.guoyuan.R;
import com.zhongxi.guoyuan.application.MyApplication;
import com.zhongxi.guoyuan.entity.coinStore.HotGoodsData;
import com.zhongxi.guoyuan.url.Url;
import com.zhongxi.guoyuan.utils.DataUtil;

import java.math.BigDecimal;
import java.util.List;

import static com.umeng.socialize.utils.DeviceConfig.context;
import static com.zhongxi.guoyuan.R.id.ivStoreImg;
import static com.zhongxi.guoyuan.R.id.tvBack;
import static com.zhongxi.guoyuan.R.id.tvCoin;
import static com.zhongxi.guoyuan.R.id.tvCoinTitle;
import static com.zhongxi.guoyuan.R.id.tv_yield;
import static com.zhongxi.guoyuan.R.id.view;

/**
 * Created by Administrator on 2017/4/12.
 */

public class RewardCoinListAdapter extends BaseAdapter {
    private List<HotGoodsData> data;
    private LayoutInflater mLayoutInflater;
    private Context mContext;

    public RewardCoinListAdapter(Context context, List<HotGoodsData> data) {
        this.mLayoutInflater = LayoutInflater.from(context);
        this.data = data;
        this.mContext = context;
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
//            convertView = mLayoutInflater.inflate(R.layout.adapter_reward_coin_list, parent, false);
            convertView = mLayoutInflater.inflate(R.layout.ad_reward_item, parent, false);
            holder.ivImg = (ImageView) convertView.findViewById(ivStoreImg);
            holder.tvName = (TextView) convertView.findViewById(tvCoinTitle);
            holder.tvCoin = (TextView) convertView.findViewById(R.id.tvCoin);
            holder.tv_yield = (TextView) convertView.findViewById(R.id.tv_yield);
            holder.tvBack = (TextView) convertView.findViewById(R.id.tvBack);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        if (null != data.get(position) && !"".equals(data.get(position))) {
            HotGoodsData list = data.get(position);
            if (null != list.getThumbnail() && !"".equals(list.getThumbnail())) {
                Glide.with(mContext).load(Url.IMG_URL + list.getThumbnail()).placeholder(R.mipmap.iv_loading).fitCenter().into(holder.ivImg);
            }
            if (null != list.getName() && !"".equals(list.getName())) {
                holder.tvName.setText(list.getName());
            } else {
                holder.tvName.setText("");
            }
            if (null != list.getPrice() && !"".equals(list.getPrice())) {
                holder.tvCoin.setText(list.getPrice() + "元");
            } else {
                holder.tvCoin.setText("0元");
            }
        }
        return convertView;
    }

    class ViewHolder {
        private ImageView ivImg;
        private TextView tvName;
        private TextView tvCoin;
        private TextView tv_yield;
        private TextView tvBack;
    }
}
